<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //then()
        //使用promise解决回调地狱
        //由pending变成 fulfilled时，执行then的第一个回调函数
        //由pending变成rejected时执行then的第二个函数

        //执行后返回的值
        //then方法执行后返回一个新的promise对象

        //实例化一个promise对象
        const p = new Promise((resolve, reject) => {
            //resolve();
            reject();
        });

        p.then(() => {
            console.log('sucess')
        }, () => {
            console.log('error');
            //在then的回调函数中 return后面的东西 会用promise包装一下
            //return undefined
            //等价于
            //默认情况下就调用resolve
            return new Promise((resolve, reject) => {
                resolve(undefined)

            });
        }).then(() => {
            console.log('success2');
            () => {
                console.log('error2');
            }
        })
    </script>
</body>

</html>